
fn main() {
    println!("Hello, world!");

    let w = 30;
    let l = 50;
    println!("{}",area(w, l));

    println!("{}",area_dim((w,l)));

    let rec = Rectangle{width:30,length:80};
    println!("{}",area_struct(&rec));
    println!("{:?}",rec);
    println!("{:#?}",rec);
    println!("{:#?}",rec.area());

    let r1 = Rectangle{width:30,length:50};
    let r2 = Rectangle{width:20,length:80};
    let r3 = Rectangle{width:40,length:90};

    println!("{}",r1.can_hold(&r2));
    println!("{}",r1.can_hold(&r3));
    println!("{}",r2.can_hold(&r3));
    println!("{}",r3.can_hold(&r2));
    println!("{}",r3.can_hold(&r1));
    println!("{:#?}",Rectangle::squar(500));
}

#[derive(Debug)]
struct Rectangle {
    width:u32,
    length:u32,
}
impl Rectangle {
    fn area(&self)->u32 {
        self.width*self.length
    }
    // 是否装得下其他长方形
    fn can_hold(&self,other:&Rectangle) -> bool{
        self.width >other.width && self.length>other.length
    }
    fn squar(size:u32) ->Rectangle{
        Rectangle{
            width:size,
            length:size,
        }
    }
}

//面积
fn area(width :u32,length: u32) -> u32{
    width*length
}
//面积
fn area_dim( dim:(u32,u32)) -> u32{
    dim.0*dim.1
}
fn area_struct(rect:&Rectangle) ->u32{
    rect.width*rect.length
}